import { Component, Output, EventEmitter } from '@angular/core';
import {TodolistsService} from '../../services/todolists.service'
@Component({
  selector: 'app-todolist-add',
  standalone: false,
  templateUrl: './todolist-add.component.html',
  styleUrl: './todolist-add.component.css'
})
export class TodolistAddComponent {
  @Output() todoAdded = new EventEmitter<void>();
  todoText: string = '';
  constructor(private TodolistsService: TodolistsService) { }
  addTodo(): void {
    if (this.todoText.trim()) {
      this.TodolistsService.addTodoList({title: this.todoText}).subscribe({
        next: (response) => {
          if (response.success) {
            // console.log('Todo added successfully:', this.todoText);
            this.todoText = '';

            this.todoAdded.emit();
          }
        },
        error: (error) => {
          console.error('Failed to add todo:', error);
        }
      })
    }
  }
}
